﻿using System.Threading;
using UnityEngine;

namespace DL.Net
{
    public class ThreadSafeLogger
    {
        private static readonly object _lock = new object();

        public static void Log(string message)
        {
            lock (_lock)
            {
                var stackTrace = new System.Diagnostics.StackTrace(1, true);
                var frame = stackTrace.GetFrame(0);
                var method = frame.GetMethod();
                var declaringType = method.DeclaringType;
                var lineNumber = frame.GetFileLineNumber();

                Debug.Log(
                    $"[{Thread.CurrentThread.ManagedThreadId}] {declaringType?.Name}.{method.Name}({lineNumber}): {message}");
            }
        }
    }
}